﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;

/// <summary>
///DropDownListEditShow 的摘要说明
/// </summary>
public class DropDownListEditShow:BaseEditShowField
{
	public DropDownListEditShow()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    public override IEnumerable<System.Web.UI.Control> GetThisTypeControl(ConfigColumns cCol, string value, bool isEdit)
    {
        DropDownList ctrl = new DropDownList();
        ctrl.ID = cCol.ColumnName + "_EditShow";
        if (!cCol.EditShowRequired)
        {
            ctrl.Items.Add(new ListItem("请选择", string.Empty));
        }

        ctrl.AppendDataBoundItems = true;
        DataTable tab = DBFactory.GetConn().exeTable(cCol.EditShowSqlText);
        ctrl.DataTextField = cCol.EditShowBindTextField;
        ctrl.DataValueField = cCol.EditShowBindValueField;

        ctrl.DataSource = tab;
        ctrl.DataBind();

        if (isEdit)
        {
            ctrl.SelectedValue = value;
        }
        else
        {
            if (!string.IsNullOrEmpty(cCol.AddShowDefaultValue))
            {
                ctrl.SelectedValue = cCol.AddShowDefaultValue;
            }
        }

        yield return ctrl;
    }
}
